Test for build commands in git subdirs
authorMatt Brubeck <mbrubeck@limpet.net>
Fri, 12 Sep 2014 22:21:23 +0000 (15:21 -0700)
committerMatt Brubeck <mbrubeck@limpet.net>
Fri, 12 Sep 2014 22:30:43 +0000 (15:30 -0700)
tests/test_cargo_compile_git_deps.rs

index 0822a7af16aaedd5109436c58564b1b92aa9bf85..0ad20e5cc8e909665685b10423dbca76a672228b 100644 (file)
@@ -1143,3 +1143,61 @@ test!(git_repo_changing_no_rebuild {
     assert_that(p1.process(cargo_dir().join("cargo")).arg("build"),
                 execs().with_stdout(""));
 })
+
+test!(git_dep_build_cmd {
+    let p = git_repo("foo", |project| {
+        project.file("Cargo.toml", r#"
+            [project]
+
+            name = "foo"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+
+            [dependencies.bar]
+
+            version = "0.5.0"
+            path = "bar"
+
+            [[bin]]
+
+            name = "foo"
+        "#)
+        .file("src/foo.rs",
+              main_file(r#""{}", bar::gimme()"#, ["bar"]).as_slice())
+        .file("bar/Cargo.toml", r#"
+            [project]
+
+            name = "bar"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+            build = "cp src/bar.rs.in src/bar.rs"
+
+            [lib]
+
+            name = "bar"
+        "#)
+        .file("bar/src/bar.rs.in", r#"
+            pub fn gimme() -> int { 0 }
+        "#)
+    }).assert();
+
+    assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
+        execs().with_status(0));
+
+    assert_that(
+      cargo::util::process(p.bin("foo")),
+      execs().with_stdout("0\n"));
+
+    // Touching bar.rs.in should cause the `build` command to run again.
+    let mut file = fs::File::create(&p.root().join("bar/src/bar.rs.in")).assert();
+    file.write_str(r#"pub fn gimme() -> int { 1 }"#).assert();
+    drop(file);
+
+    assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
+        execs().with_status(0));
+
+    assert_that(
+      cargo::util::process(p.bin("foo")),
+      execs().with_stdout("1\n"));
+})
+